<?php

include_once '../objects/growthUser.php';
include_once '../objects/growthRace.php';
include_once '../conexion.php';

class actionResult {
    
    private $conx;
    private $sql = "select f.foodcod, f.namefood, r.racecod, r.namerace, b.racebatch, b.batchcod, b.batchname, b.foodbatch, b.dateregisterb, 
                    gu.batchcod, gu.growthdate, gu.weightbirth, gu.weightpreweaning, gu.weightweaning, gu.weightpreceba, gu.weightceba, gu.agepreweaning, gu.ageweaning, gu.agepreceba, gu.ageceba
                    from food as f, race as r, batch as b, growth_user as gu where gu.batchcod = b.batchcod and gu.batchcod = '%s' and r.racecod = b.racebatch and f.foodcod='%s'";
    private $res = "SELECT resul FROM results WHERE resultcod = '%s'"; 
    private $grace = "select gr.*, r.racecod, r.namerace from growth_race as gr, race as r where gr.racecod = r.racecod and r.namerace = '%s'";
    
    public function __construct() {
       
    }
    
    public function prompt($cod){
        $resu='';
        $consult = sprintf($this->res,$cod);
        $this->conx = new conexion();
        $result = pg_exec($this->conx->getConexionDB(), $consult);
        $this->conx->closeConexionDB();
        $this->conx = null;
        $row = pg_num_rows($result);
        if ($row > 0){
                  while ($rows = pg_fetch_array($result)){             
                  $resu=$rows['resul'];
                  }
        }
        return $resu;
    }
    
    
    public function growthUser($batch,$food){
        $growth_User = new growthUser();
        $consult = sprintf($this->sql,$batch,$food);
        $this->conx = new conexion();
        $result = pg_exec($this->conx->getConexionDB(), $consult);
        $this->conx->closeConexionDB();
        $this->conx = null;
        $row = pg_num_rows($result);
        if ($row > 0){
        while ($rows = pg_fetch_array($result)){      
                $growth_User->setBatchname($rows['batchname']);
                $growth_User->setNamerace($rows['namerace']);
                $growth_User->setFoodname($rows['namefood']);
                $growth_User->setWeightbirth($rows['weightbirth']);
                $growth_User->setWeightpreweaning($rows['weightpreweaning']);
                $growth_User->setWeightweaning($rows['weightweaning']);
                $growth_User->setWeightpreceba($rows['weightpreceba']);
                $growth_User->setWeightceba($rows['weightceba']);
                $growth_User->setAgepreweaning($rows['agepreweaning']);
                $growth_User->setAgeweaning($rows['ageweaning']);
                $growth_User->setAgepreceba($rows['agepreceba']);
                $growth_User->setAgeceba($rows['ageceba']);
                $growth_User->setGrowthdate($rows['growthdate']);                
            }
            
        }
        return $growth_User;	
    }
 
     public function growthrace($race){
        $growth_race = new growthRace();
        $consult = sprintf($this->grace,$race);
        $this->conx = new conexion();
        $result = pg_exec($this->conx->getConexionDB(), $consult);
        $this->conx->closeConexionDB();
        $this->conx = null;
        $row = pg_num_rows($result);
        if($row>0){
            while ($rows = pg_fetch_array($result)){
                $growth_race->setGrowthrcod($rows['growthrcod']);
                $growth_race->setRacecod($rows['racecod']);
                $growth_race->setWeight0days($rows['weight0days']);
                $growth_race->setWeight80days($rows['weight80days']);
                $growth_race->setWeight160days($rows['weight160days']);
                $growth_race->setWeight240days($rows['weight240days']);
                $growth_race->setWeight320days($rows['weight320days']);
                $growth_race->setWeight400days($rows['weight400days']);
                $growth_race->setWeight480days($rows['weight480days']);
                $growth_race->setWeight560days($rows['weight560days']);
                $growth_race->setWeight640days($rows['weight640days']);
                $growth_race->setWeight720days($rows['weight720days']);
                $growth_race->setWeight800days($rows['weight800days']);
                $growth_race->setWeight880days($rows['weight880days']);
                $growth_race->setWeight960days($rows['weight960days']);
            }
        }
        return  $growth_race;
    }
}

?>
